package com.turing.manage.food;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import java.util.Map;

import com.turing.dao.Dao;
import com.turing.dao.DaoImpl;

public class FoodService {
	
	Dao dao = new DaoImpl();
	
	public List<Map<String, Object>> queryCourseAll() throws ClassNotFoundException, SQLException {
		return dao.executeQueryForList("select * from food");
	}

	
	/**
	 *  desc 添加方法的 执行
	 * @param course_name
	 * @param course_time
	 * @throws ClassNotFoundException
	 * @throws FileNotFoundException
	 * @throws SQLException
	 * @throws IOException
	 */
	public void addCourse(String food_name, String food_jiage,String food_geshu) throws ClassNotFoundException, FileNotFoundException, SQLException, IOException {
		String sql="insert into food values('"+(int)(Math.random()*100)+"',?,?,?)";
		
		int [] types=new int [3];
		types[0]=Types.VARCHAR;
		types[1]=Types.VARCHAR;
		types[2]=Types.VARCHAR;
		
		Object [] values=new Object[3];
		values [0]=food_name;
		values [1] =food_jiage;
		values [2] =food_geshu;
		
		dao.executeUpdate(sql, types, values);
		
		
	}


	/**
	 *  desc 
	 * @param course_id
	 * @return
	 * @throws ClassNotFoundException
	 * @throws SQLException
	 */
	public Map<String, Object> queryFoodById(String food_id) throws ClassNotFoundException, SQLException {

		
		return dao.executeQueryForMap("select * from food where food_id='"+food_id+"'");
	}


	public void updateFood(String food_id, String food_name, String food_jiage,String food_geshu) throws ClassNotFoundException, SQLException {
				
		dao.executeUpdate("update food set food_name='"+food_name+"',food_jiage='"+food_jiage+"',food_geshu='"+food_geshu+"' where food_id='"+food_id+"'");

		
	}


	public void deleteFoodByIds(String[] delids) throws ClassNotFoundException, FileNotFoundException, SQLException, IOException {
		 for(int i =0;i<delids.length;i++)
	     {
			    //2.根据课程id删除       			其他表中的信息
			String sql1 = "delete from food where food_id=?";
			
		    dao.executeUpdate(sql1, new int []{Types.VARCHAR}, new Object[]{delids[i]});
		     }
		
		
	}

	
}
